//对象冒充
/*
function ParentClass(color){
    this.color = color;
    this.showColor = function (){
        console.log(this.color);
    }
}

function SubClass1(color,name){
    console.log("对象冒充方法实现继承");
    //调用父类方法
    this.newMethod = ParentClass;
    this.newMethod(color);
    //删除父类方法调用，避免后续修改到父类方法
    delete this.newMethod;

    //...定义自己的方法
    this.name = name;
    this.showName = function(){
        console.log(this.name);
    }
}

var parent = new ParentClass("red");
var sub = new SubClass1("blue","vito");
parent.showColor();
sub.showColor();
sub.showName();




//使用Function 的call函数进行对象冒充
function SubClass2(color,name){
    console.log("调用call函数实现对象冒充");
    //调用父类方法
    ParentClass.call(this,color);

    //...定义自己的方法
    this.name = name;
    this.showName = function(){
        console.log(this.name);
    }
}

var parent = new ParentClass("red");
var sub = new SubClass2("blue","vito");
parent.showColor();
sub.showColor();
sub.showName();


//使用Function的apply函数进行对象冒充
function SubClass3(color,name){
    console.log("调用apply函数实现对象冒充");
    //调用父类方法
    //ParentClass.apply(this,new Array(color));
    ParentClass.apply(this,arguments);

    //...定义自己的方法
    this.name = name;
    this.showName = function(){
        console.log(this.name);
    }
}

var parent = new ParentClass("red");
var sub = new SubClass3("blue","vito");
parent.showColor();
sub.showColor();
sub.showName();
*/

//使用原型链模式进行继承
/*
function ParentClass2(){

}

ParentClass2.prototype.color='red';
ParentClass2.prototype.showColor = function(){
    console.log(this.color);
}

function SubClass4(){

}
SubClass4.prototype = new ParentClass2();
SubClass4.prototype.name ="";
SubClass4.prototype.showName = function(){
    console.log(this.name);
}

var parent = new ParentClass2();
var sub = new SubClass4();
parent.color = 'red';
parent.showColor();
sub.color='blue';
sub.name='vito';
sub.showColor();
sub.showName();
*/

//使用原型链加对象冒充方式进行对象继承(推荐)
function ParentClass3(color){
    this.color = color;
}
ParentClass3.prototype.showColor = function (){
    console.log(this.color);
}

function SubClass5(color,name){
    ParentClass3.call(this,color);
    this.name = name;
}

SubClass5.prototype = new ParentClass3();
SubClass5.prototype.showName = function (){
    console.log(this.name);
}

var parent = new ParentClass3("red");
var sub = new SubClass5("blue","vito");
parent.showColor();
sub.showColor();
sub.showName();
